package demo1;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 具体装饰器：过滤指定长度以下的单词
 */
public class FilterLengthDecorator extends WordReaderDecorator {
    private final int minLength; // 最小单词长度（小于该长度将被过滤）

    public FilterLengthDecorator(WordReader wordReader, int minLength) {
        super(wordReader);
        this.minLength = minLength;
    }

    @Override
    protected List<String> decorate(List<String> words) {
        List<String> filteredWords = words.stream()
                .filter(word -> word.length() >= minLength) // 过滤短单词
                .collect(Collectors.toList());
        System.out.printf("装饰器-长度过滤（最小%d位）：原始%d个单词，过滤后%d个，列表：%s%n",
                minLength, words.size(), filteredWords.size(), filteredWords);
        return filteredWords;
    }
}
